package com.yh.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.service.userService;
import com.yh.bean.PageBean;
import com.yh.service.impl.userServiceImpl;

/**
 * Servlet implementation class TextServlet2
 */
@WebServlet("/TextServlet2")
public class TextServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TextServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		

		//response.setCharacterEncoding("UTF-8");
		//PrintWriter out=response.getWriter();
		
		int defaultPage=1;
		if(request.getParameter("currenPage")!=null){
			defaultPage=Integer.parseInt(request.getParameter("currenPage").toString());
		}
		
		PageBean pb=new PageBean();
		//设置当前页，为了计算开始的索引
		pb.setCurrentPage(defaultPage);
		userService userservice=new userServiceImpl();
		//分页加载所有新闻的信息
		Map map=userservice.loadNews(pb);
		
		request.setAttribute("map", map);
		//响应页面
		//response.sendRedirect("info.jsp");
		
		request.getRequestDispatcher("info.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	  System.out.println("doPost----------------------");
	  doGet(request, response);
	}

}
